package exam.bak.bilibili;

import java.util.PriorityQueue;

public class P1 {

    public int[] GetLeastNumbers(int[] input, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int num : input) {
            queue.add(num);
        }
        int []result = new int[k];
        for(int i=0;i<k;i++){
            result[i]=queue.poll();
        }
        return result;
    }

    public static void main(String[] args) {
        int[] ints = new P1().GetLeastNumbers(new int[]{4, 5, 1, 6, 2, 7, 3, 8}, 4);
        System.out.println(ints);
    }
}
